//
//  AppDelegate.m
//  GoodBuy
//
//  Created by dlios on 15-5-13.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//


#import "AppDelegate.h"
#import "UMFeedback.h"


@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [NSThread sleepForTimeInterval:1.5];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    RootViewController *rootTBC = [[RootViewController alloc]init];
//    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:rootTBC];
    
    self.window.rootViewController = rootTBC;
//    [navi release];
    [rootTBC release];
    

    [_window release];
    
    //友盟appkey
    [UMFeedback setAppkey:@"5551988067e58eb48d00103b"];
    [UMSocialData setAppKey:@"5551988067e58eb48d00103b"];
    
    // 1.获得网络监控的管理者
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    
    // 2.设置网络状态改变后的处理
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变了, 就会调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
                self.alert = [[UIAlertView alloc]initWithTitle:@"网络切换" message:@"当前网络状态未知." delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [_alert show];
                break;
                
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                NSLog(@"没有网络(断网)");
                self.alert = [[UIAlertView alloc]initWithTitle:@"网络切换" message:@"当前为无网络状态,程序不能正常使用,请您打开手机流量或者WIFI." delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [_alert show];
                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                NSLog(@"手机自带网络");
                self.alert = [[UIAlertView alloc]initWithTitle:@"网络切换" message:@"当前网络状态为手机网络,请您尽可能少刷新,从而节省流量." delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [_alert show];
                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                NSLog(@"WIFI");
                self.alert = [[UIAlertView alloc]initWithTitle:@"网络切换" message:@"当前网络状态为WIFI,请你尽情享受本软件." delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [_alert show];
                break;
        }
    }];
    
    // 3.开始监控
    [mgr startMonitoring];
    
    return YES;
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
